<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>闭包内存泄漏</title>
</head>
<body>
<button id="btn">btn</button>
</body>
<script>

 //案例1
    let test = null
    function example() {
        var element = document.getElementById("btn")
        element.onclick = function () {
            alert("This is a leak!")
        }
         element = null // 释放element
        test = element
    }
    example()


    //案例2

    function Foo(content){
        this.content = content
    }
    let test2 = null
    function foo(){
        let n = new Foo('foo...')
        function f(){
            alert(n) // 使用n
            n = null // 释放n
            test2 = n  // 测试观察n
        }
        f()
    }
    foo()

</script>
</html>